package reflect;


import java.lang.reflect.Field;

public class ReflectDemo8 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Teacher");
        Object obj = cls.newInstance();

        Field field = cls.getDeclaredField("name");

        field.set(obj,"张三");
        System.out.println(field.get(obj));

        Field field1 = cls.getField("age");
        field1.set(obj,18);
        System.out.println(field1.get(obj));

        Field[] field2 = cls.getDeclaredFields();
        for (Field f : field2) {
            System.out.println(f.getName());
        }
    }
}
